﻿int xsize;           // each size is 8 units 
 int zsize;                    // each size is 8 units  








float metalUpkeep; 
 float energyUpkeep; 
 float metalMake;    // metal will always be created  float makesMetal;   
 // metal will be created when unit is on and enough energy can be drained  float energyMake; 
 float metalCost;  float energyCost; 
 float buildTime; 
 float extractsMetal;  
float extractRange; 
 float windGenerator; 
 float tidalGenerator; 
 float metalStorage; 
 float energyStorage; 
  bool extractSquare; 
 bool isMetalMaker;  
 float autoHeal;  
  //amount autohealed 
 float idleAutoHeal;  //amount autohealed only during idling 
 int idleTime;    //time a unit needs to idle before its considered idling  
 float power;
 float health; 
 unsigned int category;  
 float speed; 
 float turnRate;
 bool turnInPlace; 
 float turnInPlaceDistance; //!< units above this distance to goal will try to turn while keeping    
       //!< some of their speed. 0 to disable 
 float turnInPlaceSpeedLimit; //!< units below this speed will turn in place regardless of their    
       //!< turnInPlace setting  
int moveType;  
bool upright;
  bool collide; 
  float controlRadius;  
float losRadius; 
 float airLosRadius;  
float losHeight;  
 int radarRadius; 
 int sonarRadius; 
 int jammerRadius; 
 int sonarJamRadius; 
 int seismicRadius; 
 float seismicSignature; 
 bool stealth; 
 bool sonarStealth; 
  bool  buildRange3D; 
 float buildDistance; 
 float buildSpeed; 
 float reclaimSpeed; 
 float repairSpeed; 
 float maxRepairSpeed; 
 float resurrectSpeed; 
 float captureSpeed; 
 float terraformSpeed; 
  float mass;  
 bool pushResistant; 
 bool strafeToAttack;                               //should the unit move sideways when it can't shoot? 
 float minCollisionSpeed;
  float slideTolerance;  float maxSlope; 
 float maxHeightDif;                  //maximum terraform height this building allows 
 float minWaterDepth; 
 float waterline;  
 float maxWaterDepth;  
 float armoredMultiple; 
 int armorType; 
  int flankingBonusMode; // 0: no flanking bonus               
          // 1: global coords, mobile                         // 2: unit coords, mobile           
              // 3: unit coords, locked 
 float3 flankingBonusDir; // units takes less damage when attacked from this dir (encourage flanking fire) 
 float  flankingBonusMax; // damage factor for the least protected direction 
 float  flankingBonusMin; // damage factor for the most protected direction  float  flankingBonusMobilityAdd;
 // how much the ability of the flanking bonus direction to move builds up each frame   UnitModelDef modelDef; 
 /*  float collisionSphereScale; 
 float3 collisionSphereOffset; 
 bool useCSOffset;  */  
 std::string scriptName;  // the name of the unit's script, e.g. "armjeth.cob" 
 std::string scriptPath;  // the path of the unit's script, e.g. "scripts/armjeth.cob" 
  std::string collisionVolumeType;  // can be "Ell", "CylT" (where T is one of "XYZ"), or "Box" 
 float3 collisionVolumeScales;    // the collision volume's full axis lengths 
 float3 collisionVolumeOffsets; 
   // relative to the unit's center position 
 int collisionVolumeTest;      // 0: discrete, 1: continuous   
 struct UnitDefWeapon {    UnitDefWeapon();    UnitDefWeapon(std::string name, const WeaponDef* def, int slavedTo,                  float3 mainDir, float maxAngleDif, unsigned int badTargetCat,                  unsigned int onlyTargetCat, float fuelUse);    std::string name;    const WeaponDef* def;    int slavedTo;   
 float3 mainDir;   
 float maxAngleDif;  
  float fuelUsage;             //how many seconds of fuel it costs for the owning unit to fire this weapon  
  unsigned int badTargetCat; 
   unsigned int onlyTargetCat;  }; 
 std::vector<UnitDefWeapon> weapons; 
 const WeaponDef* shieldWeaponDef; 
 const WeaponDef* stockpileWeaponDef; 
 float maxWeaponRange; 
 float maxCoverage;  
 std::map<int, 
std::string> buildOptions; 
  std::string type; 
 std::string tooltip;  
std::string wreckName; 
  std::string deathExplosion;
  std::string selfDExplosion;  
 std::string TEDClassString;  // these might be changed later for something better 
 std::string categoryString;  
 std::string buildPicName; 
 mutable UnitDefImage* buildPic; 
  mutable CIcon iconType;  
 bool canSelfD; 
 int selfDCountdown;  
 bool canSubmerge; 
 bool canfly; 
 bool canmove; 
 bool canhover; 
 bool floater; 
 bool builder; 
 bool activateWhenBuilt;  
bool onoffable; 
 bool fullHealthFactory; 
 bool factoryHeadingTakeoff; 
  bool reclaimable; 
 bool capturable; 
 bool repairable;  
 bool canRestore; 
 bool canRepair; 
 bool canSelfRepair;  
bool canReclaim;
  bool canAttack;  
bool canPatrol; 
 bool canFight; 
 bool canGuard; 
 bool canBuild; 
 bool canAssist; 
 bool canBeAssisted;  
bool canRepeat; 
 bool canFireControl; 
  int fireState; 
 int moveState;  
 //aircraft stuff 
 float wingDrag; 
 float wingAngle; 
 float drag; 
 float frontToSpeed; 
 float speedToFront; 
 float myGravity; 
  float maxBank; 
 float maxPitch;
  float turnRadius;
  float wantedHeight; 
 float verticalSpeed; 
 bool canCrash;  bool hoverAttack; 
 bool airStrafe; 
 float dlHoverFactor;
 // < 0 means it can land, >= 0 indicates how much the unit will move during hovering on the spot 
 bool DontLand () const { return dlHoverFactor >= 0.0f; } 
 bool bankingAllowed; 
  float maxAcc; 
 float maxDec; 
 float maxAileron; 
 float maxElevator; 
 float maxRudder; 
 float crashDrag;  
 MoveData* movedata;//  unsigned char* yardmapLevels[6];
  unsigned char* yardmaps[4];// Iterations of the Ymap for building rotation  
 int xsize;           // each size is 8 units 
 int zsize;                    // each size is 8 units  
 int buildangle;  
 float loadingRadius; // for transports 
 float unloadSpread; 
 int transportCapacity; 
 int transportSize; 
 int minTransportSize; 
 bool isAirBase; 
 bool isFirePlatform;   
           // should the carried units still be able to shoot? 
 float transportMass;
  float minTransportMass; 
 bool holdSteady; 
 bool releaseHeld; 
 bool cantBeTransported; 
 bool transportByEnemy; 
 int transportUnloadMethod;      
      // 0 - land unload, 1 - flyover drop, 2 - land flood 
 float fallSpeed;                // dictates fall speed of all transported units  float unitFallSpeed;              // sets the transported units fbi, overrides fallSpeed  
 bool canCloak;             
     // if the unit can cloak 
 bool startCloaked;                // if the units want to start out cloaked 
 float cloakCost;      
          // energy cost per second to stay cloaked when stationary 
 float cloakCostMoving;              // energy cost per second when moving 
 float decloakDistance;              // if enemy unit come within this range decloaking is forced 
 bool decloakSpherical;              // use a spherical test instead of a cylindrical test? 
 bool decloakOnFire;   // should the unit decloak upon firing 
  bool canKamikaze; //self destruct if enemy come to close 
 float kamikazeDist;  
 bool targfac; 
 bool canDGun; 
 bool needGeo; 
bool isFeature;  
bool hideDamage;  
bool isCommander;  bool showPlayerName;  
 bool canResurrect;  
bool canCapture;  
int highTrajectoryType;    
          // 0 (default) = only low, 1 = only high, 2 = choose  
 unsigned int noChaseCategory;  
 struct SoundStruct {    GuiSoundSet select;    GuiSoundSet ok; 
   GuiSoundSet arrived;   
 GuiSoundSet build;   
 GuiSoundSet repair;  
  GuiSoundSet working;    GuiSoundSet underattack;  
  GuiSoundSet cant;   
 GuiSoundSet activate; 
   GuiSoundSet deactivate;  }; 
 SoundStruct sounds; 
  bool leaveTracks; 
 float trackWidth;  
float trackOffset; 
 float trackStrength; 
 float trackStretch; 
 int trackType; 
  bool canDropFlare; 
 float flareReloadTime; 
 float flareEfficiency;  
float flareDelay; 
 float3 flareDropVector; 
 int flareTime;  
int flareSalvoSize; 
 int flareSalvoDelay; 
  bool smoothAnim;                // True if the unit should use interpolated animation  
bool canLoopbackAttack;   // only matters for fighter aircraft 
 bool levelGround;     
           // only matters for buildings  
 bool useBuildingGroundDecal;  int buildingDecalType; 
 int buildingDecalSizeX; 
 int buildingDecalSizeY;  
float buildingDecalDecaySpeed;
   bool showNanoFrame;  // Does the nano frame animation get shown during construction? 
 bool showNanoSpray;                // Does nano spray get shown at all? 
 float3 nanoColor;     // If nano spray is displayed what color is it?  
 float maxFuel;    // max flight time in seconds before the aircraft needs to return to a air repair bay to refuel 
 float refuelTime;  // time to fully refuel unit  
float minAirBasePower; // min build power for airbases that this aircraft can land on   
std::vector<CExplosionGenerator*> sfxExplGens; // list of explosion generators for use in scripts  
std::string pieceTrailCEGTag; // base tag (eg. "flame") of CEG attached to pieces of exploding units 
 int pieceTrailCEGRange;     // range of piece CEGs (0-based, range 8 ==> tags "flame0", ..., "flame7") 
  int maxThisUnit; // number of units of this type allowed simultaneously in the game 





static const int COBSCALE = 65536;
static const int COBSCALEHALF = COBSCALE / 2;
static const float CORDDIV   = 1.0f / COBSCALE;
static const float RAD2TAANG = COBSCALEHALF / PI;
static const float TAANG2RAD = PI / COBSCALEHALF; 




//Command documentation from http://visualta.tauniverse.com/Downloads/cob-commands.txt
//And some information from basm0.8 source (basm ops.txt) 
//Model interaction
const int MOVE       = 0x10001000;
const int TURN       = 0x10002000;
const int SPIN       = 0x10003000;
const int STOP_SPIN  = 0x10004000;
const int SHOW       = 0x10005000;
const int HIDE       = 0x10006000;
const int CACHE      = 0x10007000;
const int DONT_CACHE = 0x10008000;
const int MOVE_NOW   = 0x1000B000;
const int TURN_NOW   = 0x1000C000;
const int SHADE      = 0x1000D000;
const int DONT_SHADE = 0x1000E000;
const int EMIT_SFX   = 0x1000F000;
 //Blocking operations
const int WAIT_TURN  = 0x10011000;
const int WAIT_MOVE  = 0x10012000;
const int SLEEP      = 0x10013000;
 //Stack manipulation
const int PUSH_CONSTANT    = 0x10021001;
const int PUSH_LOCAL_VAR   = 0x10021002;
const int PUSH_STATIC      = 0x10021004;
const int CREATE_LOCAL_VAR = 0x10022000;
const int POP_LOCAL_VAR    = 0x10023002;
const int POP_STATIC       = 0x10023004;
const int POP_STACK        = 0x10024000;
    // Not sure what this is supposed to do 
//Arithmetic operations
const int ADD         = 0x10031000;
const int SUB         = 0x10032000;
const int MUL         = 0x10033000;
const int DIV         = 0x10034000;
const int MOD      = 0x10034001; 
 // spring specific
const int BITWISE_AND = 0x10035000;
const int BITWISE_OR  = 0x10036000;
const int BITWISE_XOR = 0x10037000;
const int BITWISE_NOT = 0x10038000;
 //Native function calls
const int RAND           = 0x10041000;
const int GET_UNIT_VALUE = 0x10042000;
const int GET            = 0x10043000;
 //Comparison
const int SET_LESS             = 0x10051000;
const int SET_LESS_OR_EQUAL    = 0x10052000;
const int SET_GREATER          = 0x10053000;
const int SET_GREATER_OR_EQUAL = 0x10054000;
const int SET_EQUAL            = 0x10055000;
const int SET_NOT_EQUAL        = 0x10056000;
const int LOGICAL_AND          = 0x10057000;
const int LOGICAL_OR           = 0x10058000;
const int LOGICAL_XOR          = 0x10059000;
const int LOGICAL_NOT          = 0x1005A000;
 //Flow control
const int START           = 0x10061000;
const int CALL            = 0x10062000;
 // converted when executed
const int REAL_CALL       = 0x10062001;
 // spring custom
const int LUA_CALL        = 0x10062002;
 // spring custom
const int JUMP            = 0x10064000;
const int RETURN          = 0x10065000;
const int JUMP_NOT_EQUAL  = 0x10066000;
const int SIGNAL          = 0x10067000;
const int SET_SIGNAL_MASK = 0x10068000;
 //Piece destruction
const int EXPLODE    = 0x10071000;
const int PLAY_SOUND = 0x10072000;
 //Special functions
const int SET    = 0x10082000;
const int ATTACH = 0x10083000;
const int DROP   = 0x10084000;
 // Indices for SET, GET, and GET_UNIT_VALUE for LUA return values
#define LUA0 110 
// (LUA0 returns the lua call status, 0 or 1)
#define LUA1 111
#define LUA2 112
#define LUA3 113
#define LUA4 114
#define LUA5 115
#define LUA6 116
#define LUA7 117
#define LUA8 118
#define LUA9 119 
 //Handy macros
#define GET_LONG_PC() (script.code[PC++])//#define POP() (stack.size() > 0) ? stack.back(), stack.pop_back(); : 0


    = getFunctionId("Create"); 
   = getFunctionId("StartMoving"); 
   = getFunctionId("StopMoving");  
    = getFunctionId("Activate");   
   = getFunctionId("Killed"); 
 = getFunctionId("Deactivate");
  = getFunctionId("SetDirection"); 
  = getFunctionId("SetSpeed"); 
  = getFunctionId("RockUnit"); 
  = getFunctionId("HitByWeapon");  
   = getFunctionId("MoveRate0"); 
    = getFunctionId("MoveRate1"); 
  = getFunctionId("MoveRate2"); 
    = getFunctionId("MoveRate3");  
 = getFunctionId("setSFXoccupy"); 
 = getFunctionId("HitByWeaponId"); 
   // Also add the weapon aiming stuff  for (int i = 0; i < COB_MaxWeapons; ++i)
 {    char buf[15]; 
   sprintf(buf, "Weapon%d", i + 1);  
  string weapon(buf);    sprintf(buf, "%d", i + 1); 
   string weapnum(buf);   
 scriptIndex[COBFN_QueryPrimary   + i] 
= getFunctionId("Query"   + weapon);    scriptIndex[COBFN_AimPrimary     + i] 
= getFunctionId("Aim"     + weapon);    scriptIndex[COBFN_AimFromPrimary + i] 
= getFunctionId("AimFrom" + weapon);    scriptIndex[COBFN_FirePrimary    + i] 
= getFunctionId("Fire"    + weapon);    scriptIndex[COBFN_EndBurst       + i] 
= getFunctionId("EndBurst"     + weapnum);    scriptIndex[COBFN_Shot           + i] 
= getFunctionId("Shot"         + weapnum);    scriptIndex[COBFN_BlockShot      + i] 
= getFunctionId("BlockShot"    + weapnum);    scriptIndex[COBFN_TargetWeight   + i]
 = getFunctionId("TargetWeight" + weapnum); 







const int COBFN_Create = 0;
const int COBFN_StartMoving = 1;
const int COBFN_StopMoving = 2;
const int COBFN_Activate = 3;
const int COBFN_Killed = 4;
const int COBFN_Deactivate = 5;
const int COBFN_SetDirection = 6;
const int COBFN_SetSpeed = 7;
const int COBFN_RockUnit = 8;
const int COBFN_HitByWeapon = 9;
const int COBFN_MoveRate0 = 10;
const int COBFN_MoveRate1 = 11;
const int COBFN_MoveRate2 = 12;
const int COBFN_MoveRate3 = 13;
const int COBFN_SetSFXOccupy = 14;
const int COBFN_HitByWeaponId = 15;
const int COBFN_Last = 16; 
         //Make sure to update this, so the array will be sized properly 
// These are special (they need space for MaxWeapons of each)const int COB_MaxWeapons = 32;
const int COBFN_QueryPrimary   = COBFN_Last;
const int COBFN_AimPrimary     = COBFN_QueryPrimary   + COB_MaxWeapons;
const int COBFN_AimFromPrimary = COBFN_AimPrimary     + COB_MaxWeapons;
const int COBFN_FirePrimary    = COBFN_AimFromPrimary + COB_MaxWeapons;
const int COBFN_EndBurst       = COBFN_FirePrimary    + COB_MaxWeapons;
const int COBFN_Shot           = COBFN_EndBurst       + COB_MaxWeapons;
const int COBFN_BlockShot      = COBFN_Shot           + COB_MaxWeapons;
const int COBFN_TargetWeight   = COBFN_BlockShot      + COB_MaxWeapons;
const int COBFN_Weapon_Funcs   = 8; 












